﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using DAL;
public partial class Admin_Article_Add_Article : System.Web.UI.Page
{
    public string channelId_temp = "";
    public string classId_temp = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            this.channelId_temp = Request["channelID"];
            this.classId_temp = Request["Class_ID"];
            this.classId_droplist.Attributes.Add("onchange", "onChangeVal()");
            this.channelId_droplist.Attributes.Add("onchange", "load(this.options[this.selectedIndex].value)");
            this.hits_text.Attributes.Add("onblur", "isNumber(this.value)");
            this.addArtBtn.Attributes.Add("onclick", "return checkVal();");
            BindAllData(this.channelId_temp, this.classId_temp);
        }
    }
    #region 数据初始绑定
    public void BindAllData(string _channelId, string _classId)
    {
        try
        {
            string str = "SELECT Count(0) FROM T_Channel";
            int channelList = int.Parse(DbHelperSQL.GetSingle(str).ToString());
            if (channelList == 0)
            {
                Common.JsMsg.ShowAndRedirect(this.Page, "对不起!目前暂无任何频道存在，请先添加频道后再添加文章！", "InforChannel/ChannelAnd.aspx");
            }
            else
            {
                BindDropDownList_Channel();
                if (_channelId != "")
                {
                    channelId_droplist.SelectedValue = _channelId;
                }
            }
            artFrom_text.Text = "福建ASP.NET技术专业站";
            hits_text.Text = "100";
            artUrl_text.Text = "www.fjaspx.com";
            createDate_text.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            modiDate_text.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            this.author_text.Text = "福建ASP.NET技术专业站";
            this.inputerl_text.Text = "系统管理员";
        }
        catch { }
    }
    #endregion

    #region 绑定频道数据
    public void BindDropDownList_Channel()
    {
        try
        {
            channelId_droplist.DataSource = new Channel().GetList("IsShow=1");
            channelId_droplist.DataTextField = "ChannelName";
            channelId_droplist.DataValueField = "OrderId";
            channelId_droplist.DataBind();
        }
        catch { }
    }
    #endregion

    #region   添加文章
    protected void addArtBtn_Click(object sender, EventArgs e)
    {
        if (FCKeditor1.Value == "")
        {
            Common.JsMsg.Alert("请输入文章内容！");
        }
        if (channelId_droplistVal.Value != "" && classId_droplistVal.Value != "" && artDes_text.Text != "" && artKeyword_text.Text != "" && FCKeditor1.Value != "")
        {
            int result = 0;
            Model.Article model = new Model.Article();
            model.Area = this.ClassID.Value;
            model.ArtAdmin = this.inputerl_text.Text;
            model.ArtAuthor = this.author_text.Text;
            model.ArtColor = "#FFFFFF";
            model.ArtContent = FCKeditor1.Value;
            model.ArtCount = 0;
            model.ArtDate = Convert.ToDateTime(createDate_text.Text);
            model.ArtHome = artFrom_text.Text;
            model.ArtInfo = artDes_text.Text;
            model.ArtKeyword = artKeyword_text.Text;
            model.ArtReview = "NULL";
            model.ArtReviewcount = int.Parse(hits_text.Text);
            model.ArtTitle = title_text.Text;
            model.ArtTitle2 = subtitle_text.Text;
            model.ArtUrl = artUrl_text.Text;
            model.CatId = int.Parse(classId_droplistVal.Value);
            model.ChannelId = int.Parse(channelId_droplistVal.Value);
            model.Images = this.picPath.Text;
            if (isPic_text.Checked)
                model.IsImg = 1;
            else model.IsImg = 0;

            if (isTop_cbox.Checked)
                model.IsTop = 1;
            else
                model.IsTop = 0;
            if (stateNow_lable.Checked)
                model.Passed = 1;
            else model.Passed = 0;
            if (isTj_cbox.Checked)
                model.Recommend = 1;
            else
                model.Recommend = 0;
            model.UpdateDate = Convert.ToDateTime(modiDate_text.Text);
            result = new Article().Add(model);
            if (result != 1)
                Common.JsMsg.MsgBoxRedrect("添加文章成功！", "Article_Manage.aspx", this.Page);
            else
                Common.JsMsg.MsgBoxRedrect("出现异常！添加文章失败！", "Article_Manage.aspx", this.Page);
        }
        else
        {
            Common.JsMsg.Alert("请选择类别");
        }
    }
    #endregion

}
